/**
 *	Copyright (c) TeamFlamingo And gray 2004-2009
 *	www.me-live.com.cn / www.i-gray.cn
 *
 *	[ WARNING ]
 *		This is NOT a freeware!
 *		You MUST get author's authorization before using it!
 *	[ WARNING ]
 *
 *	Name : widget.js / Development Code Evolve
 *	Created / Modify : 2010-3-24 / --
 */

var	widget	=	Class({
	hash	:	function ( local )
	{
		return	hash.substr( local, 12 );
	},

	//	[CH]	验证电子邮件
	isEmail	:	function ( str )
	{
		return /^[\w\.]+@([A-Z_a-z0-9-]+\.)+[a-z0-9A-Z]{2,4}$/.test( str );
	},

	//	[CH]	验证用户名
	isUsername	:	function ( str )
	{
		return	/^[\w\.]{4,20}$/.test( str );
	},

	//	[CH]	验证验证码
	isNumber	:	function ( str )
	{
		return	/^[\d]{5}$/.test( str );
	},

	//	[CH]	清除非法字符
	uh			:	function ( str )
	{
		var	str	=	str.replace( /<(\/?)(script|i?frame|style|html|body|title|link|meta|\?|\%)([^>]*?)>/ig, '' );
		var	str	=	str.replace( /(<[^>]*)on[a-zA-Z]+\s*=([^>]*>)/ig, '' );
		return	str;
	},

	clearFromWord	:	function(html)
	{
		// for Word2000+
		html = html.replace(/<\/?SPAN[^>]*>/gi, "" );
		html = html.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3");
		html = html.replace(/<(\w[^>]*) style="([^"]*)"([^>]*)/gi, "<$1$3");
		html = html.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3");
		html = html.replace(/<\\?\?xml[^>]*>/gi, "");
		html = html.replace(/<\/?\w+:[^>]*>/gi, "");
		// for Word2000
		html = html.replace(/<img+.[^>]*>/gi, "");
		return html;
	},

	//	[CH]	使用Ajax POST数据会造成将&识别为分割符
	//	[CH]	这里先用#好替换
	htmlentities	:	function ( str )
	{
		return str.replace( /&/g, '#amp;' ).replace( /</g, '#lt;' ).replace( />/g, '#gt;' );
	},

	html_entity_decode	:	function ( str )
	{
		return str.replace( /&amp;/g, '&' ).replace( /&lt;/g, '<' ).replace( /&gt;/g, '>' );
	}
});